package com.gitee.demo.ah;

import com.alibaba.fastjson.JSON;
import com.gitee.demo.constants.HttpHeaderContentTypeEnum;
import com.gitee.demo.httpclient.MyHttpsClient;
import com.gitee.demo.utils.AESUtils;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import static com.gitee.demo.ah.AHIdentifyServiceHttps.httpsGetScanTask;
import static com.gitee.demo.ah.AHIdentifyServiceHttps.httpsPostLogin;

/**
 * @author Tao on 2019/12/11
 */
public class demo {
    private static final String ACCOUNT = "admin";
    private static final String PASSWORD = "1qaz@WSX";
    private static final String LOGINURL = "https://192.168.31.33/api/v2/login";
    private static final String SCANTASKURL = "https://192.168.31.33/api/v2/scantask?offset=0&limit=10&currentStatuses=6";
    private static final String url="https://192.168.38.230:10024/report/baseLine/down_report?module=3&taskId=1&reportType=excel";

    public static void main(String[] args) {

        String token = httpsPostLogin(ACCOUNT, PASSWORD, LOGINURL);
        String result = httpsGetScanTask(token, SCANTASKURL);
        System.out.println(result);

//        String s = httpsPostSZ();
//        System.out.println(s);
//        String s1 = httpsGetSZ();
//        System.out.println(s1);

    }

    public static String httpsPostSZ() {
        //参数
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("taskId", 1);
        paramsMap.put("fileType", "excel");

        //post请求
        Object result = null;
        try {
            result = MyHttpsClient.sendPostHttps(url, paramsMap, getHeadersMap(), HttpHeaderContentTypeEnum.X_WWW_FORM.getKey());

        } catch (Throwable e) {
            return null;
        }

        return JSON.toJSONString(result);
    }

    public static String httpsGetSZ() {
        //参数
        Map<String, Object> paramsMap = new HashMap<String, Object>();

        //get请求
        Object result = null;
        try {
            result = MyHttpsClient.sendGetHttps(url, paramsMap, getHeadersMap());
        } catch (Throwable e) {
            return null;
        }

        return JSON.toJSONString(result);
    }


    public static Map<String, String> getHeadersMap(){

        Map<String, String> headersMap = new HashMap<String, String>();
        headersMap.put("Authorization", "Bearer 14e9c246d5791541d4b2e688801e882b");
        headersMap.put("Cookie", "sessionTimeout=; shiroSessionId=d9d03f74-d23f-4ae9-aac3-da82f9c46a7b; token=; JSESSIONID_10004=cxglrtzt3yxd12j88si4w8232");

        return headersMap;

    }

}
